package org.je.io.file;

import java.io.File;
import java.io.FileOutputStream;

/**
 * @author fanyifeng
 */
public class FileWriter
{
	/**
	 * @param file
	 * @param data
	 * @param append
	 */
	public static void write(File file, byte[] data, boolean append) {
		FileOutputStream out = null;
		try {
			out = new FileOutputStream(file,append);
			out.write(data);
			out.flush();
		} catch (Exception ex) {
			throw new RuntimeException("write-error:" + file.getPath() + ", " + ex.getMessage());
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (Exception e) {}
			}
		}
	}

	/**
	 * @param path
	 * @param data
	 */
	public static void cover(String path, byte[] data) {
		write(new File(path) ,data ,false);
	}

	public static void append(String path, byte[] data) {
		write(new File(path) ,data ,true);
	}

}
